package com.hcc.repository.extension.interceptor;

import com.hcc.repository.core.constants.SqlTypeEnum;
import com.hcc.repository.core.interceptor.HandlerInterceptor;
import com.hcc.repository.core.interceptor.SqlExecuteContext;

/**
 * 扩展的Interceptor
 *
 * @author hushengjun
 * @date 2023/4/9
 */
public interface ExtHandlerInterceptor extends HandlerInterceptor {

    @Override
    default void beforeExecute(Object handler, Object[] parameters, SqlExecuteContext context) {
        if (SqlTypeEnum.SELECT.equals(context.getSqlType())) {
            this.beforeExecuteQuery(handler, parameters, context);
        } else {
            this.beforeExecuteUpdate(handler, parameters, context);
        }
    }

    /**
     * 更新之前调用
     * @param handler
     * @param parameters
     * @param context
     */
    default void beforeExecuteUpdate(Object handler, Object[] parameters, SqlExecuteContext context) {}

    /**
     * 查询之前调用
     * @param handler
     * @param parameters
     * @param context
     */
    default void beforeExecuteQuery(Object handler, Object[] parameters, SqlExecuteContext context) {}

}
